/**
 * 聊天室相关API
 * 封装所有聊天室相关的网络请求
 */

import http from '../http.js';

/**
 * 获取聊天室列表
 * @param {Object} params - 查询参数
 * @param {number} params.pageNum - 页码
 * @param {number} params.pageSize - 每页数量
 * @param {string} params.roomName - 搜索关键词
 */
export const getChatrooms = (params) => {
	return http.get('/chatroom', params);
};

/**
 * 获取聊天室详情
 * @param {number} roomId - 聊天室ID
 */
export const getChatroomDetail = (roomId) => {
	return http.get(`/chatroom/${roomId}`);
};

/**
 * 创建聊天室
 * @param {Object} data - 聊天室信息
 * @param {string} data.roomName - 聊天室名称
 * @param {string} data.roomDesc - 聊天室简介
 */
export const createChatroom = (data) => {
	return http.post('/chatroom/create', data);
};

/**
 * 删除聊天室
 * @param {number} roomId - 聊天室ID
 */
export const deleteChatroom = (roomId) => {
	return http.delete(`/chatroom/${roomId}`);
};

/**
 * 获取聊天室消息列表
 * @param {number} roomId - 聊天室ID
 * @param {Object} params - 查询参数
 * @param {number} params.pageNum - 页码
 * @param {number} params.pageSize - 每页数量
 */
export const getChatroomMessages = (roomId, params) => {
	return http.get(`/chatroom/${roomId}/messages`, params);
};

/**
 * 发送消息
 * @param {Object} data - 消息数据
 * @param {number} data.roomId - 聊天室ID
 * @param {string} data.type - 消息类型（text/image）
 * @param {string} data.content - 消息内容
 */
export const sendMessage = (data) => {
	return http.post('/chatroom/message/send', data);
};

/**
 * 加入聊天室
 * @param {number} roomId - 聊天室ID
 */
export const joinChatroom = (roomId) => {
	return http.post(`/chatroom/${roomId}/join`);
};

/**
 * 退出聊天室
 * @param {number} roomId - 聊天室ID
 */
export const leaveChatroom = (roomId) => {
	return http.post(`/chatroom/${roomId}/leave`);
};

/**
 * 上传图片
 * @param {string} filePath - 图片路径
 */
export const uploadChatroomImage = (filePath) => {
	return http.upload('/chatroom/upload/image', filePath);
};

export default {
	getChatrooms,
	getChatroomDetail,
	createChatroom,
	deleteChatroom,
	getChatroomMessages,
	sendMessage,
	joinChatroom,
	leaveChatroom,
	uploadChatroomImage
};

